package com.intelligent.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.pojo.CustomerReconciliationDetail;
import com.intelligent.service.CustomerReconciliationDetailService;
import com.intelligent.utils.Result;
import com.intelligent.vo.ReconciliationDetailPageReq;
import com.intelligent.vo.ReconciliationDetailResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/customer-reconciliation-detail")
public class CustomerReconciliationDetailController {

    @Autowired
    private CustomerReconciliationDetailService detailService;

    @PostMapping("add")
    public Result<?> add(@RequestBody CustomerReconciliationDetail detail) {
        boolean ok = detailService.addDetail(detail);
        return ok ? Result.success(detail) : Result.error("保存失败");

    }

    @PostMapping("/page")
    public Result<Page<ReconciliationDetailResp>> page(@RequestBody ReconciliationDetailPageReq req) {
        Page<ReconciliationDetailResp> page = detailService.pageDetails(req);
        return Result.success(page);
    }

    @GetMapping("/{id}")
    public Result<ReconciliationDetailResp> detail(@PathVariable Long id) {
        ReconciliationDetailResp resp = detailService.getDetail(id);
        if (resp == null) return Result.error("未找到明细");
        return Result.success(resp);
    }
}
